<template>
  <div class="card_cover">
    <p v-if="data">
      <a href="/home">主页 ></a>
      <a href="">{{ data.book_type }} ></a>
      <a href=""> {{ data.book_title }} </a>
    </p>
    <p>
      <a href="/home/login" @click.prevent="toCollection"> 加入书架 </a>
      <a href="/home/comment" @click.prevent="toComment"> 热门评论 </a>
    </p>
  </div>
</template>

<script>
import { useRouter } from 'vue-router';
import { useStore } from "vuex";
import { addBook } from "../../api/data";
export default {
  props: ["data"],
  setup(props) {
    
    const router=useRouter()
    const store = useStore();
    const toCollection = async () => {
      if (store.state.userdata == null) {
        return alert("请先登陆");
      }

      let user_id = store.state.userdata._id;
      let book_id = props.data._id;
      let chapter_id = "";
      // console.log(user_id, book_id, collection_data);

      await addBook({
        user_id,
        book_id,
        chapter_id
      });

      // alert(data1.msg);
    };
    const toComment=async ()=>{
        router.push({path:"/home/comment",query:{
          book_id:props.data._id
        }})
    }

    return {
      toCollection,
      toComment
    };
  },
};
</script>

<style lang="scss" scoped>
.card_cover {
  display: flex;
  justify-content: space-between;
  height: 41px;
  align-items: center;
  background-color: #e1eced;
  border-bottom: 1px solid #88c6e5;
  padding: 15px;
  p {
    height: 41px;
    display: flex;
    align-items: center;
    a {
      font-size: 14px;
      color: #333;
      &:hover {
        color: crimson;
      }
    }

    &:nth-of-type(2) {
      a {
        display: flex;
        background-color: #459df5;
        padding: 5px 5px;
        color: #fff;
        margin-right: 10px;
        font-size: 12px;
      }
    }
  }
}
</style>